package Homework.apiDay05;

public class TryCatchDemo {

    public static void main(String[] args) {
        String s=null;
        String s1="abc";
        try {
            //System.out.println(s.length());
            System.out.println("try");
            System.out.println(s1.charAt(5));
            return;
        }catch (NullPointerException e){
            e.printStackTrace();
            System.out.println("抓到空指针异常");
        }catch (IndexOutOfBoundsException e) {
            e.printStackTrace();
            System.out.println("下标越界异常");
        }finally {
            System.out.println("finally块");
        }

        try {
            //System.out.println(s.length());
            System.out.println(s1.charAt(5));
        }catch (NullPointerException|IndexOutOfBoundsException e){
            e.printStackTrace();
            System.out.println("抓到空指针异常或下标越界异常");
        }catch (Exception e) {
            System.out.println("出了个错");
        }finally {
            System.out.println("finally块");
        }

        System.out.println("结束");

    }
}
